<template lang="pug">
  div
    s-table(
      v-if="$route.name === 'remote_task' || $route.name === 'remote_taskIssue'"
      ref="table"
      :column="tableObj.column"
      :filterProps="{items: filterItems}"
      :queryFn="tableObj.getList"
      rowKey="taskId"
      title="任务列表"
      )
      .table-operator(slot="table-operator" v-if="$route.name === 'remote_task'" v-action:add)
        el-button(size="small" type="success" @click="$router.push({ path: '/remote/task/add' })") 添加任务
      template(slot="taskWay" slot-scope="text, scope") {{dictFilter(text, 'SCEN_TASK_WAY')}}
      template(slot="taskStas" slot-scope="text, scope") {{dictFilter(text, 'SCEN_TASK_STAS')}}
      template(slot="chkProp" slot-scope="text") {{text ? text + '%' : '--'}}
      template(slot="action" slot-scope="text, scope")
        el-link(type="primary" :underline="false" @click="$router.push({path: '/remote/task/info', query: { id: scope.taskId}})" v-action:info) 详情
        template(v-if="pageName === 'remote_taskIssue'")
          el-link.ml5(type="warning" :underline="false" v-if="scope.taskStas === '0' || scope.taskStas === '4'" @click="operatorHandle(1, scope)" v-action:taskIssue) 下发
          template(v-action:issueDelete)
            el-popconfirm(title="确定删除该任务吗？" v-if="scope.taskStas === '0'" @confirm="operatorHandle(2, scope)" @onConfirm="operatorHandle(2, scope)")
              el-link.ml5(type="danger" :underline="false" slot="reference") 删除
            el-popconfirm(title="确定撤回该任务吗？" v-if="scope.taskStas === '2' || scope.taskStas === '1'" @confirm="operatorHandle(3, scope)" @onConfirm="operatorHandle(3, scope)")
              el-link.ml5(type="danger" :underline="false" slot="reference") 撤回
    router-view(v-else)
    distribute-modal(:visible.sync="issueObj.visible" :id="issueObj.id" :orgName="issueObj.orgName" :percent="issueObj.percent" @getList="refreshTable")
</template>
<script>
import { STable } from '@/components'
import { taskList, deleteHandle } from '@/api/remote'
import DistributeModal from '../distribute/DistributeModal'

const column = [
  {
    prop: 'sort',
    label: '序号'
  },
  {
    prop: 'taskDscr',
    label: '任务描述'
  },
  {
    prop: 'medinsName',
    label: '所属医院',
    align: 'center'
  },
  {
    prop: 'taskWay',
    label: '添加方式',
    align: 'center'
  },
  {
    prop: 'taskStas',
    label: '任务状态',
    align: 'center'
  },
  {
    prop: 'chkProp',
    label: '查房比例',
    align: 'center'
  },
  {
    prop: 'crteTime',
    label: '添加日期',
    align: 'center'
  },
  {
    prop: 'taskBegntime',
    label: '开始时间',
    align: 'center'
  },
  {
    prop: 'taskEndtime',
    label: '结束时间',
    align: 'center'
  },
  {
    prop: 'crterName',
    label: '添加人'
  },
  {
    prop: 'isuName',
    label: '下发人'
  },
  {
    prop: 'bchno',
    label: '批次号',
    align: 'center'
  },
  {
    prop: 'action',
    label: '操作',
    width: '164',
    align: 'center'
  }
]

export default {
  name: 'RemoteAddList',
  components: {
    STable,
    DistributeModal
  },
  data () {
    return {
      tableObj: {
        column,
        getList: taskList
      },
      issueObj: {
        id: '',
        visible: false,
        orgName: '',
        percent: ''
      }
    }
  },
  computed: {
    pageName () {
      return this.$route.name
    },
    filterItems () {
      return [
        {
          key: 'medinsId',
          label: '医疗机构',
          type: 'orgselect',
          selectType: 1
        },
        {
          key: 'admdvs',
          label: '医保区',
          type: 'selectdict',
          dictKey: 'admdvsList'
        },
        {
          key: 'taskStas',
          label: '任务状态',
          type: 'selectdict',
          dictKey: 'SCEN_TASK_STAS'
        },
        {
          key: 'Date',
          label: '添加日期',
          type: 'daterange',
          formatFlag: true
        }
      ]
    }
  },
  created () {
  },
  methods: {
    // 刷新表格
    refreshTable (flag = false) {
      this.$refs.table.refresh(flag)
    },
    /**
     * description: 表格操作句柄
     * @return {type} 1: 下发，2: 删除，3：撤回
     */
    operatorHandle (type, scope) {
      if (type === 1) {
        this.issueObj = {
          id: scope.taskId,
          visible: true,
          orgName: scope.medinsName,
          percent: scope.chkProp
        }
        return
      }
      // taskStas(1删除，2撤回)
      deleteHandle({ taskId: scope.taskId, taskStas: type === 2 ? 1 : 2 }).then(() => {
        this.$message.success('提交成功')
        this.refreshTable()
      })
    }
  }
}
</script>
